/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package graphicsystem;

/**
 *
 * @author DiegoAl
 */
public class Rectangle {

    private Point leftUpVertex;
    private Point rightDownVertex;
    
    public Rectangle(Point point1, Point point2) throws InvalidPoints{
        if(point1.getAbcissa() < point2.getAbcissa() && 
                point1.getOrdinate() > point2.getOrdinate()) {
            
                    leftUpVertex = point1;
                    rightDownVertex = point2;
                    
        }else{
            throw new InvalidPoints();
        }
    }

    public Point getLeftUpVertex() {
        return leftUpVertex;
    }

    public void setLeftUpVertex(Point leftUpVertex) {
        this.leftUpVertex = leftUpVertex;
    }

    public Point getRightDownVertex() {
        return rightDownVertex;
    }

    public void setRightDownVertex(Point rightDownVertex) {
        this.rightDownVertex = rightDownVertex;
    }
    
    public boolean intersection(Rectangle rectangle){
        if(this.leftUpVertex.getAbcissa()< rectangle.rightDownVertex.getAbcissa() &&
                this.leftUpVertex.getOrdinate() > rectangle.rightDownVertex.getOrdinate() &&
                this.rightDownVertex.getAbcissa() < rectangle.leftUpVertex.getAbcissa() &&
                this.rightDownVertex.getOrdinate() < rectangle.leftUpVertex.getOrdinate()){
            return true;
        }
        return false;
    }
    
}
